<?php

/**
 * Album class
 */
class str_SmugMugAlbum extends str_SmugMugEntity {
    
    private $_albumImages = null;
    
    /**
     * Returns list of all images from this album
     * @return array
     */
    public function getImages() {
        if ($this->_albumImages === null) {
    		$result = $this->_phpSmug->images_get("AlbumID={$this->getId()}", "AlbumKey={$this->getKey()}", "Heavy=1");
    	    foreach($result['Images'] as $imageDataSet) {
    	        $this->_albumImages[] = new str_SmugMugImage($imageDataSet, $this->_phpSmug, $this);
    	    }
        }
        return $this->_albumImages;
    }
    
    /**
     * Returns random image object from this album
     * @return str_SmugMugImage
     */
    public function getRandomImage() {
        $imagesList = $this->getImages();
        $imagesCount = count($imagesList);
        if (!is_array($imagesList) || $imagesCount == 0) {
            return null;
        }
        return $imagesList[rand(0, $imagesCount - 1)];
    }
    
    /**
     * Returns album URL
     * @return string
     */
    public function getUrl() {
        return 'http://smugmug.com/gallery/' . $this->getId() . '_' . $this->getKey();
    }
    
    /**
     * Returns album title
     * @return 
     */
    public function getTitle() {
        if ($this->isNullObject()) {
            return '';
        }
        
        $data = $this->getData();
        return isset($data['Title']) ? $data['Title'] : '';
    }
    
}